<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>学生总分信息</title>
    <link rel="stylesheet" href="element.css">
</head>
<body>
<div id="stu" style="width:80%;margin:0 auto">
    <h2>学生信息总分</h2>
    <el-row>
        <el-col :span="6">
            <el-button type="success" round @click="dialogFormVisible = true">新增</el-button>
            <el-input style="width:60%" v-model="clazz" placeholder="请输入一个班级" @keyup.enter.native="search"></el-input>
        </el-col>
    </el-row>

    <el-dialog title="学生总分" :visible.sync="dialogFormVisible">
        <el-form :model="stuSumScore">
            <el-form-item label="学生姓名" :label-width="formLabelWidth">
                <el-input v-model="stuSumScore.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="学生年龄" :label-width="formLabelWidth">
                <el-input v-model="stuSumScore.age" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="学生性别" :label-width="formLabelWidth">
                <el-select v-model="stuSumScore.gender" placeholder="请选择性别">
                    <el-option label="男生" value="男"></el-option>
                    <el-option label="女生" value="女"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="学生班级" :label-width="formLabelWidth">
                <el-input v-model="stuSumScore.clazz" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="学生总分" :label-width="formLabelWidth">
                <el-input v-model="stuSumScore.sumScore" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="cancel">取 消</el-button>
            <el-button type="primary" @click="add">确 定</el-button>
        </div>
    </el-dialog>

    <el-table
            :data="stuSumScoreData"
            stripe
            style="width: 100%">
        <el-table-column
                prop="name"
                label="姓名"
                width="180">
        </el-table-column>
        <el-table-column
                prop="age"
                label="年龄"
                width="180">
        </el-table-column>
        <el-table-column
                prop="gender"
                label="性别">
        </el-table-column>
        <el-table-column
                prop="clazz"
                label="班级">
        </el-table-column>
        <el-table-column
                prop="sumScore"
                label="总分">
        </el-table-column>
        <el-table-column
                label="操作">
            <template slot-scope="scope">
                <el-button type="primary" icon="el-icon-edit" circle @click="edit(scope.row)"></el-button>
                <el-button type="danger" icon="el-icon-delete" circle @click="del(scope.row.id)"></el-button>
            </template>
        </el-table-column>
    </el-table>
    <el-row type="flex" class="row-bg" justify="center">
        <el-pagination
                :page-size="pageSize"
                :pager-count="11"
                layout="prev, pager, next"
                :total="totalElements"
                :current-page.sync="pageNum"
                @current-change="loadTable">
        </el-pagination>
    </el-row>

</div>

<script src="jquery.min.js"></script>
<script src="vue.js"></script>
<script src="element.js"></script>
<script>
    new Vue({
      el: '#stu',
      data:{
        stuSumScoreData:[],
        pageSize:10,
        pageNum:1,
        totalElements:0,
        dialogFormVisible: false,
        stuSumScore: {},
        formLabelWidth: '80px',
        clazz:''
      },
      // 在页面被创建的时候会执行一次
      created(){
        this.loadTable();
      },
      methods:{
        loadTable(){
            $.get("/stuSumScore/getAllByPageWithClazzOption?pageSize="+this.pageSize+"&pageNum="+this.pageNum+"&clazz="+this.clazz).then(res=>{
                this.stuSumScoreData = res.data.content;
                this.totalElements = res.data.totalElements;
            });
        },
        del(id){
            // 向后端发起一个delete请求，根据id进行删除
            $.ajax({
                url: '/stuSumScore/del/'+id,
                type: 'delete',
                contentType: 'application/json'
            }).then(res=>{
                if(res.code==='200'){
                    this.loadTable();
                }
            })
        },
        add(){
            this.dialogFormVisible = false;
            $.ajax({
                url:'/stuSumScore/addOrEdit',
                type:'put',
                contentType: 'application/json',
                data: JSON.stringify(this.stuSumScore)
            }).then(res=>{
                this.stuSumScore = {};
                this.loadTable();
            })

        },
        edit(row){
            console.log(row);
            this.stuSumScore = row;
            this.dialogFormVisible = true;
        },
        cancel(){
            this.dialogFormVisible = false;
            this.stuSumScore = {};
        },
        search(){
            console.log(this.clazz);
            this.loadTable();
        }

      }
    });



</script>


</body>
</html>